﻿using System;
using Framework.MVC;
using Identity.Model;
using Account.Model;
using Account.Model.Behavior;
using Framework.MVVM.Model;
using Account.IService;
using Account.Service;
using Identity.IService;
using Identity.Service;

namespace FrontCenter.Models
{
    [ServiceAttribute(typeof(IAnswerService), typeof(AnswerService), "Instance")]
    [ServiceAttribute(typeof(IIdentityService), typeof(IdentityService), "Instance")]
    public class QueryAnswerModel : AsyncModelBase, IValidateIdentity, IQueryAnswer
    {
        #region Field

        private const string m_resource_user = "getpassword";

        private const string m_user = "user";
        private const string m_result = "result";

        #endregion Field

        #region AsyncModelBase

        protected override void OnInit(Type type)
        {
            this.OnBeginRequest();
            this.ValidateIdentity(m_resource_user, string.Empty, string.Empty, string.Empty);
        }

        #endregion AsyncModelBase

        #region IValidateIdentity

        public string IdentityCode { get; set; }

        public bool IsOnce { get; set; }

        public string Source { get; set; }

        public void OnValidateIdentityComplete(string key, Identity.IService.Entry.IdentityEntry entry)
        {
            AccountCode = entry.value;
            this.QueryAnswer(m_user, string.Empty, string.Empty);
        }

        public void OnValidateIdentityError(string key)
        {
            this.OnEndRequest();
        }

        #endregion IValidateIdentity

        #region IQueryAnswer

        public string AccountCode { get; set; }

        public string Answer { get; set; }

        public bool AnswerAsc { get; set; }

        public int AnswerPage { get; set; }

        public int AnswerSize { get; set; }

        public string AnswerSort { get; set; }

        public void OnQueryAnswerComplete(string key, Account.IService.Entry.QueryResult<Account.IService.Entry.ResourceEntity<string>> entry)
        {
            OnComplete(m_result, entry);
            this.OnEndRequest();
        }

        public void OnQueryAnswerError(string key)
        {
            this.OnEndRequest();
        }

        public string QuestionCode { get; set; }

        #endregion IQueryAnswer

        
    }
}